package com.junglone.gateway.admin.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import com.junglone.gateway.admin.dao.MongoDao;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;

/**
 * Description: MongoDB 数据操作抽象类
 * 
 * @author junglone: <a href="mailto:cjlnzb@hotmail.com">cjlnzb@hotmail.com</a>
 * @since 2021/04/04 00:20
 */
public abstract class AbstractMongoDaoImpl<T> implements MongoDao<T> {

	@Resource
	private MongoTemplate mongoTemplate;
	
    @Override
    public T insert(T object) {

       return mongoTemplate.insert(object);
    }


    @Override
    public void save(T object) {
        mongoTemplate.save(object);
    }
    
	@Override
	public T findOne(Query query, Class<T> entityClass) {
		return mongoTemplate.findOne(query, entityClass);
	}

    @Override
    public long count(Query query, Class<T> entityClass) {
        return mongoTemplate.count(query, entityClass);
    }

    @Override
    public List<T> findAll(Query query, Class<T> entityClass) {
        return mongoTemplate.find(query, entityClass);
    }

    @Override
    public UpdateResult update(Query query, Update update, Class<T> entityClass) {
        return mongoTemplate.updateFirst(query, update, entityClass);
    }

    @Override
    public void createCollection(String collectionName) {

    }

    @Override
    public DeleteResult remove(Query query, Class<T> entityClass) {
        return mongoTemplate.remove(query, entityClass);
    }
}
